package com.quanxiaoha.weblog.admin.controller;

import com.quanxiaoha.weblog.admin.model.vo.announcement.*;
import com.quanxiaoha.weblog.admin.service.AdminAnnouncementService;
import com.quanxiaoha.weblog.common.PageResponse;
import com.quanxiaoha.weblog.common.Response;
import com.quanxiaoha.weblog.common.domain.dos.AnnouncementVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/admin/announcement")
public class AdminAnnouncementController {

    @Autowired
    private AdminAnnouncementService announcementService;

    /**
     * 保存公告（新增公告）
     *
     * @param saveAnnouncementReqVO
     * @return
     */
    @PostMapping("/save")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response saveAnnouncement(@RequestBody @Validated SaveAnnouncementReqVO saveAnnouncementReqVO) {
        log.info("进入到----保存公告");
        return announcementService.saveAnnouncement(saveAnnouncementReqVO);
    }

    /**
     * 删除公告
     *
     * @param deleteAnnouncementReqVO
     * @return
     */
    @PostMapping("/delete")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteAnnouncement(@RequestBody @Validated DeleteAnnouncementReqVO deleteAnnouncementReqVO) {
        return announcementService.deleteAnnouncement(deleteAnnouncementReqVO);
    }

    /**
     * 获取公告分页列表
     *
     * @param findAnnouncementPageListReqVO
     * @return
     */
    @PostMapping("/list")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public PageResponse<AnnouncementVO> findAnnouncementPageList(@RequestBody @Validated FindAnnouncementPageListReqVO findAnnouncementPageListReqVO) {
        return announcementService.findAnnouncementPageList(findAnnouncementPageListReqVO);
    }

    /**
     * 获取公告详情
     *
     * @param findAnnouncementDetailReqVO
     * @return
     */
    @PostMapping("/detail")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response<AnnouncementVO> findAnnouncementDetail(@RequestBody @Validated FindAnnouncementDetailReqVO findAnnouncementDetailReqVO) {
        return announcementService.findAnnouncementDetail(findAnnouncementDetailReqVO);
    }
}